package com.ruoyi.civil.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.civil.domain.CivilEnginneeringFacility;
import com.ruoyi.civil.service.ICivilEnginneeringFacilityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 土建结构设施管理Controller
 *
 * @author 小赵
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/civil/facility")
public class CivilEnginneeringFacilityController extends BaseController
{
    @Autowired
    private ICivilEnginneeringFacilityService civilEnginneeringFacilityService;



    @PreAuthorize("@ss.hasPermi('civil:facility:list')")
    @GetMapping("/list")
    public TableDataInfo list(CivilEnginneeringFacility civilEnginneeringFacility)
    {
        startPage();
        List<CivilEnginneeringFacility> list = civilEnginneeringFacilityService.selectCivilEnginneeringFacilityList(civilEnginneeringFacility);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('civil:facility:export')")
    @Log(title = "土建结构设施管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CivilEnginneeringFacility civilEnginneeringFacility)
    {
        List<CivilEnginneeringFacility> list = civilEnginneeringFacilityService.selectCivilEnginneeringFacilityList(civilEnginneeringFacility);
        ExcelUtil<CivilEnginneeringFacility> util = new ExcelUtil<CivilEnginneeringFacility>(CivilEnginneeringFacility.class);
        util.exportExcel(response, list, "土建结构设施管理数据");
    }


    @PreAuthorize("@ss.hasPermi('civil:facility:query')")
    @GetMapping(value = "/{facilityId}")
    public AjaxResult getInfo(@PathVariable("facilityId") Long facilityId)
    {
        return AjaxResult.success(civilEnginneeringFacilityService.selectCivilEnginneeringFacilityByFacilityId(facilityId));
    }


    @PreAuthorize("@ss.hasPermi('civil:facility:add')")
    @Log(title = "土建结构设施管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CivilEnginneeringFacility civilEnginneeringFacility)
    {
        if (civilEnginneeringFacility.getFacilityName()==null){
            return new AjaxResult().error("请输入设施名称");
        }
        return toAjax(civilEnginneeringFacilityService.insertCivilEnginneeringFacility(civilEnginneeringFacility));
    }


    @PreAuthorize("@ss.hasPermi('civil:facility:edit')")
    @Log(title = "土建结构设施管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CivilEnginneeringFacility civilEnginneeringFacility)
    {
        return toAjax(civilEnginneeringFacilityService.updateCivilEnginneeringFacility(civilEnginneeringFacility));
    }


    @PreAuthorize("@ss.hasPermi('civil:facility:remove')")
    @Log(title = "土建结构设施管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilityIds}")
    public AjaxResult remove(@PathVariable Long[] facilityIds)
    {
        return toAjax(civilEnginneeringFacilityService.deleteCivilEnginneeringFacilityByFacilityIds(facilityIds));
    }
}
